﻿<!DOCTYPE html>
<html>
<head>
    <title>文本素材s</title>
    <link rel="Stylesheet" type="text/css" href="${os.mcss}" />
</head>
<body>

    <div class="tabarea1">
        <div id="area" class="area" style="overflow-y:auto;margin:10px 0">
            <form action="" method="post">
                <div class="form" id="form1">
                    <input type="hidden" field="Id" />
                    <div class="fl">
                        <div class="label"><span class="red">*</span>素材Key：</div>
                        <div class="in">
                            <input type="text" class="tb_normal ui-validate" summary="{required:'不能为空!',length:'必须为1-20位，且不包含非法字符'}" field="ResKey" id="resKey" />
                        </div>
                    </div>
                    <div class="fl">
                        <div class="label"><span class="red">*</span>内容：</div>
                        <div class="in">
                            <div id="contentinfo" style="width: 620px;">
                                <span>建议：使用一键排版功能可以快速生成有格式的内容。<br /><br /></span>
                                <textarea id="editor" field="Content" style="overflow: hidden; width: 620px; height: 300px;">${content}</textarea>
                            </div>
                        </div>
                    </div>
                    
                    <div class="fl">
                        <div class="label"></div>
                        <div class="in">
                            <a id="btn" class="btn" href="javascript:;">保存</a>
                        </div>
                    </div>


                </div>
            </form>
        </div>

    </div>

    <script type="text/javascript" src="${os.mjs}"></script>
<!-- 编辑器 -->
<!--
<script type="text/javascript" src="/framework/assets/editor/minpack.js"></script>
<script type="text/javascript" src="/framework/assets/editor/plugins/code/prettify.js"></script>
<script type="text/javascript">
        var editor = null;
        function initEditor() {
            editor = KindEditor.create('#editor', {
                cssPath: '/framework/assets/editor/plugins/code/prettify.css',
                uploadJson: '/framework/assets/editor/handler/upload_json.ashx',
                fileManagerJson: '/framework/assets/editor/handler/file_manager_json.ashx',
                allowFileManager: true,
                filterMode: false
            });
        }
    </script>
    -->
    <script type="text/javascript">
        var entity = ${entity} ||{};
        $JS.json.bind('form1',entity);

       // initEditor();

        var resKey = $JS.$("resKey");

        resKey.onblur = function () {
            if (this.value == '') {
                $JS.validator.setTip(this, false, 'required');
            } else {
                this.value = this.value.toLowerCase();
                if (!/[^@#\$!]{1,20}$/.test(this.value)) {
                    $JS.validator.setTip(this, false, 'length');
                } else {
                    var t = resKey;
                    $JS.validator.setTip(this, false, null,'检测中');
                    $JS.xhr.jsonPost('checkResKey', { id: entity.Id, resKey: this.value }, function(json){
                        if (json.result) {
                            $JS.validator.removeTip(t);
                        } else {
                            $JS.validator.setTip(t, false, null,'素材KEY已经存在!');
                        }
                    });
                }
            }
        };



        window.saveData = function () {
            if ($JS.validator.validate()) {
                var data=$JS.json.toObject('form1');
                //data.Content = editor.html();
                $JS.xhr.jsonPost(
                   "SaveTextRes",data,
                     function (json) {
                         if (json.result) {  
                             var d = $JS.dialog.getDialog();
                             if(d.window.refresh){
                                 d.window.refresh();
                             }
                             d.close();
                             parent.M.alert(json.message);

                         } else {
                             parent.M.alert(json.message);
                         }
                     });
            }
        };

        cms.$('btn').onclick = window.saveData;
        cms.validator.init('form1');
    </script>
</body>
</html>
